<?php
	class FoodinfoAction extends Action{
		/**
		 * 查询菜单
		 * Enter description here ...
		 */
		public function index(){
			$foodinfo=M('foodinfo');
			$list = $foodinfo->select();
			$this->assign('list',$list);
			$this->display();
		}
		/**
		 * 上传菜单
		 * Enter description here ...
		 */
		public function add(){
			if($_FILES['foodimg']['size']>0){
				$a=$this->up();
				if(isset($a)){
					$data['foodpath']=$a[0]['savename'];
				}else{
					$this->error("上传文件出错，请与系统管理员联系");
				}
			}
			$foodinfo=M('foodinfo');
			$data['foodname']=$_POST['foodname'];
			$data['money']=$_POST['money']*10;
//			
//			if($foodinfo->data($data)->add()){
//				$this->success('上传成功');
//			}else{
//				$this->error("写入数据库失败");
//			}
		}
		
		/**
		 * 菜单图片处理
		 * Enter description here ...
		 */
		private function up(){
			import('@.Org.UploadFile');
			$upload = new UploadFile();
			$upload->maxSize='1000000';//上传大小，默认-1，是不限制
			$upload->savePath=UPLOAD_FOODIMG_PATH;//保存到什么地方
			$upload->saveRule=uniqid;//上传文件名保存规则
			$upload->uploadReplace=true;//如果存在同名文件是否覆盖
			$upload->allowExts=array('jpg','jpeg','png','gif');//准许上传的后缀
			$upload->allowTypes=array('image/png','image/jpg','image/pjpeg','image/gif','image/jpeg');
			
			$upload->thumb=true;//是否开启文件缩略图
			$upload->thumbMaxWidth='200';//缩略图，如果需要多个用，分隔
			$upload->thumbMaxHeight='100';
			$upload->thumbPrefix='s_';//缩略图文件前缀
			$upload->thumbPath="";//缩略图保存路径，如果空，直接上传至。。
			$upload->thumbRemoveOrigin=1;//如果生成缩略图，是否删除原图
			$upload->subType='date';//子目录创建方式，默认hash也可以设为date
			$upload->autoSub=true; //是否使用子目录保存上传文件

			if($upload->upload()){
				$info=$upload->getUploadFileInfo();
				dump($info);
				return $info;
			}else{
				//专门来获取上传的错误信息
				$this->error($upload->getErrorMsg());
			}
		}
	}